home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
t_os
/
et
/
src
/
custom.c
< prev
next >
Wrap
Text File
|
1993-07-08
|
2KB
|
99 lines
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int set_digit(char s_a[], char *c_p, int i);
int set_i(char s_a[], char *c_p, int i);
int set_drive(char s_a[], char *c_p, int i);
char nl_a[] = {0x0d, 0x0a, '\0'};
void main()/*custom*/
{
FILE *File, *Temp;
char *c_p, c_a[80], *s_p, s_a[80];
int i;
static char op_a[] = "IMVRSTUWX";
File = fopen("custom.h", "rb");
Temp = fopen("etc.h", "wb");
while (fgets(c_a, 999, File)) {
c_p = c_a;
while (*c_p && *c_p++ != '-')
;
if (!*c_p)
continue;
while (*c_p == ' ' || *c_p == '\t')
c_p++;
i = islower(*c_p) ? *c_p - 'a' + 'A' : *c_p;
if (!strchr(op_a, i))
continue;
strcpy(s_a, "#define\to_");
switch(i) {
case 'I':
case 'M':
i = set_digit(s_a, c_p, i);
if (!i)
continue;
break;
case 'V':
case 'R':
case 'S':
case 'T':
case 'U':
case 'X':
i = set_i(s_a, c_p, i);
break;
case 'W':
i = set_drive(s_a, c_p, i);
if (!i)
continue;
break;
}
fwrite(s_a, sizeof(char), i, Temp);
}
fclose(File);
fclose(Temp);
}
int set_digit(char s_a[], char *c_p, int i)/*custom*/
{
static char c_a[] = "?\t";
char *s_p;
c_a[0] = i;
strcat(s_a, c_a);
c_p++;
s_p = c_p;
if (!isdigit(*c_p))
return(0);
while (isdigit(*c_p))
c_p++;
*c_p = '\0';
strcat(s_a, s_p);
strcat(s_a, nl_a);
return(strlen(s_a));
}
int set_i(char s_a[], char *c_p, int i)/*custom*/
{
static char c_a[] = "?";
c_a[0] = i;
strcat(s_a, c_a);
strcat(s_a, nl_a);
return(strlen(s_a));
}
int set_drive(char s_a[], char *c_p, int i)/*custom*/
{
static char c_a[] = "?\t\047?\047";
int j;
c_a[0] = i;
c_p++;
if (!islower(*c_p) && !isupper(*c_p))
return(0);
j = islower(*c_p) ? *c_p - 'a' + 'A' : *c_p;
c_a[3] = j;
strcat(s_a, c_a);
strcat(s_a, nl_a);
return(strlen(s_a));
}